package game;



import org.lwjgl.input.Keyboard;
import AGFX.F3D.F3D;
import AGFX.F3D.Camera.TF3D_Camera;
import AGFX.F3D.Light.TF3D_Light;
import AGFX.F3D.Model.TF3D_Model;

/**
 * @author Baskervil
 *
 */
public class TMenu {
	
	public TF3D_Camera Camera;
	public TF3D_Model model;
	public TF3D_Model carpet;
	public TF3D_Model singleplayer;
	public TF3D_Model multiplayer;
	public TF3D_Model exit;
	
	public TF3D_Model menu;
	public int menu_selector = 1;
	public boolean switchit1 = false;
	public boolean switchit2 = false;

	
	public TMenu(){
		F3D.Worlds.CreateWorld("MENU");
		F3D.Worlds.SetWorld("MENU");

		F3D.Viewport.Clear(0f, 0f, 0f, 1f);
		
		this.Camera = new TF3D_Camera("Menu_Camera");
		this.Camera.SetPosition(0.0f, 0.0f,15f);

		this.Camera.ctype = F3D.CAMERA_TYPE_FPS;
		
		F3D.Cameras.Add(this.Camera);
		F3D.Worlds.SetCamera(this.Camera);
	
		
		// Add light to scene
		TF3D_Light light = new TF3D_Light("light_0", 0);
		light.SetPosition(0f, 0f, 1f);
		light.spot_constant_att = 0.001f;
		light.Enable();	

		
		this.model = new TF3D_Model("cursor");
		this.model.AssignMesh("abstract::zeton.a3da");
		this.model.SetPosition(-5f, 1f, 0f);
		
		this.carpet = new TF3D_Model("carpet");
		this.carpet.AssignMesh("abstract::carpet.a3da");
		this.carpet.SetPosition(0f, 0f, -1f);
		
		this.singleplayer = new TF3D_Model("singleplayer");
		this.singleplayer.AssignMesh("abstract::singleplayer.a3da");
		this.singleplayer.SetPosition(-6f, 4f, -0.5f);
		
		this.multiplayer = new TF3D_Model("multiplayer");
		this.multiplayer.AssignMesh("abstract::singleplayer.a3da");
		this.multiplayer.ChangeSurface("singleplayer", "multiplayer");
		this.multiplayer.SetPosition(6f, 4f, -0.5f);
		
		this.exit = new TF3D_Model("exit");
		this.exit.AssignMesh("abstract::singleplayer.a3da");
		this.exit.ChangeSurface("singleplayer", "exit");
		this.exit.SetPosition(0f, -4f, -0.5f);

	}
	
	public float px(int percento){
		return (F3D.Config.r_display_width/100)*percento;
	}

	public float py(int percento){
		return (F3D.Config.r_display_height/100)*percento;
	}
	
	public void rotateModel(){
		if (this.model.GetRotation().y > 360f){
			this.model.SetRotation(0f,0f,180f);
		}
		this.model.SetRotation(0f,this.model.GetRotation().y+0.5f, 180f);
	}
	
	public int moveCursor(){
		if (Keyboard.isKeyDown(Keyboard.KEY_UP))
		{
			if (this.switchit1 == false & this.menu_selector > 1){
				this.model.SetPosition(this.model.GetPosition().x, this.model.GetPosition().y+2,this.model.GetPosition().z);
				this.menu_selector--;
			}
			this.switchit1 = true;
			return 0;
		}
		
		if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))
		{
			if (this.switchit2 == false & this.menu_selector < 4){
				this.model.SetPosition(this.model.GetPosition().x, this.model.GetPosition().y-2,this.model.GetPosition().z);
				this.menu_selector++;
			}
			this.switchit2 = true;
			return 0;
		}
			this.switchit1 = false;
			this.switchit2 = false;
		return 0;
	}
	
}
